//动态时间显示组件
const dynamicdatetime = defineComponent({
    props: [],
    emits: [],
    setup() {
        const datetimestr = ref('')

        function refreshDateTimeStr() {
            let date = new Date();
            let year = date.getFullYear();
            let month = date.getMonth() + 1;
            let day = date.getDate();
            let hour = date.getHours();
            let minute = date.getMinutes();
            let second = date.getSeconds();
            let weekday = date.getDay();
            datetimestr.value =
                DateUtil.date2nlStr(date) + '    '
                + year + '年'
                + month.toString().padStart(2, '0') + '月'
                + day.toString().padStart(2, '0') + '日    '
                + hour.toString().padStart(2, '0') + "时"
                + minute.toString().padStart(2, '0') + "分"
                + second.toString().padStart(2, '0') + "秒    "
                + DateUtil.weekdayNumber2Str(weekday)
            ;
        }

        refreshDateTimeStr();

        let intervalId;
        onMounted(() => {
            intervalId = setInterval(() => {
                refreshDateTimeStr();
            }, 1000);
            //console.log('setInterval '+intervalId);
        });

        onUnmounted(() => {
            clearInterval(intervalId);
            //console.log('clearInterval '+intervalId);
        });

        return {datetimestr};
    },
    template: `
    <p style="font-weight: bold; white-space: pre;"><slot></slot>{{ datetimestr }}</p>
    `
});